<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>新增商品</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="{{URL::asset('layui/css/layui.css')}}"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<form class="layui-form" action="">

<fieldset class="layui-elem-field site-demo-button" style="margin-top: 20px;">
    <legend>商品颜色</legend>
    <div style="margin-top: 10px;" class="color_div">
        <div class="layui-form-item">
            <label class="layui-form-label">颜色</label>
            <div class="layui-input-inline">
                <input type="text" id="color_name" name="color_name" autocomplete="off" placeholder="颜色名称" class="layui-input">
            </div>
            <div class="layui-input-inline">
                <div class="layui-upload" style="width:300px;">
                    <button type="button" class="layui-btn layui-btn-normal" id="test8">选择文件</button>
                    <button type="button" class="layui-btn" id="test9">开始上传</button>
                </div>
            </div>
        </div>
    </div>
</fieldset>

</form>

<script src="{{URL::asset('layui/layui.js')}}" charset="utf-8"></script>
<script src="{{URL::asset('js/jquery-3.1.1.min.js')}}"></script>
<script>
    layui.use(['form','upload'], function(){
        var form = layui.form
            ,upload = layui.upload
            ,layer = layui.layer;

        //选完文件后不自动上传
        upload.render({
            elem: '#test8'
            ,url: '/upload/'
            ,data:{"color_name":$('#color_name').val()}
            ,auto: false
            //,multiple: true
            ,bindAction: '#test9'
            ,done: function(res){
                if (res.code==200){
                    layer.msg("商品颜色上传成功");
                    setTimeout(function () {
                        window.parent.location.reload();
                    },500)
                }else{
                    layer.msg("商品颜色上传失败");
                }
            }
        });

    });
</script>

</body>
</html>